package com.situ.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springboot.mapper.CommentMapper;
import com.situ.springboot.pojo.query.CommentQuery;
import com.situ.springboot.pojo.vo.CommentVO;
import com.situ.springboot.service.ICommentService;
import com.situ.springboot.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// Alt+Enter
@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;


    @Override
    public PageResult list(CommentQuery commentQuery) {
        //开启分页
        PageHelper.startPage(commentQuery.getPage(), commentQuery.getLimit());
        //1、查找当前页的数据
        List<CommentVO> list = commentMapper.list(commentQuery);
        //2、查询总的数量
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return new PageResult(0, "", totalCount, list);
    }

    @Override
    public void deleteById(Integer id) {
        commentMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        // delete from student where id in(1,2,34)
        for (Integer id : ids) {
            commentMapper.deleteById(id);
        }
    }
}
